package za.co.dylanjaneke.airdownloader.model.vo
{
	import mx.collections.ArrayCollection;
	import mx.rpc.AsyncToken;
	
	import za.co.dylanjaneke.airdownloader.util.ViLogger;

	[Bindable]
	public class ShowVO
	{
		private static const log:ViLogger=
			new ViLogger(ShowVO);
		
		public var episodeKey:String;
		public var episodeName:String;
		public var showName:String;
		public var seasonNumber:String;
		public var episodeNumber:String;

		public var asyncToken:AsyncToken;
		
		public var children:ArrayCollection;
		public var isLink:Boolean=false;
		public var url:String;
		public var urlTitle:String;
		public var ticked:Boolean=false;
		
		public function ShowVO(showName:String=null, episodeName:String=null, episodeKey:String=null)
		{
			this.children= new ArrayCollection();
			
			if(showName!=null)
			{
				this.showName= showName;
				this.episodeName= episodeName;
				this.episodeKey= episodeKey;
				
				var keyArgs:Array= episodeKey.split("/");
				this.seasonNumber= 
					keyArgs[2].replace("season-","");
				this.episodeNumber=
					keyArgs[3].replace("episode-","");
				
				this.seasonNumber= 
					this.seasonNumber.length == 1 ? "0"+this.seasonNumber: this.seasonNumber;
				this.episodeNumber=
					this.episodeNumber.length == 1 ? "0"+this.episodeNumber: this.episodeNumber;
				
				
				log.info("ShowVO[episodeKey="+this.episodeKey+", episodeName="+this.episodeName +
					",showName="+this.showName+",season="+this.seasonNumber+",episode="+episodeNumber+"]");	
			}
			else
			{
				isLink= true;	
			}
		}
		
		public function get label(): String
		{
			if(isLink)
			{
				return url;
			}
			
			//return showName + " S" + seasonNumber + "E" + episodeNumber + "\n" + episodeName;
			return  "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>"+
					 	"<span fontWeight='bold'>"+showName +" - S" + seasonNumber + "E" + episodeNumber + "</span><br/>"+
						"   " + episodeName + " ["+ children.length + " link" + (children.length==1?"":"s") + "]" +
					"</TextFlow>";
		}
	}
}